package com.yolov8.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.List;

@Data
@Component
@ConfigurationProperties(prefix = "app")
public class AppConfig {

    private static ResourceLoader resourceLoader;

    @Autowired
    private ResourceLoader nonStaticResourceLoader;

    private Model model;
    private Rtmp rtmp;
    private Queue queue;

    @PostConstruct
    public void init() {
        resourceLoader = nonStaticResourceLoader;
    }

    @Data
    public static class Model {
        private String directory;
        private double defaultConfidence;
        private String pullUrl;
        private List<String> classNames;
        private String filePath;

        public Resource getDirectoryResource() throws IOException {
            return resourceLoader.getResource(directory);
        }
    }

    @Data
    public static class Rtmp {
        private String pushUrl;
    }

    @Data
    public static class Queue {
        private int pullMaxSize;
        private int pushMaxSize;
    }
}